// pages/setphone/setphone.js
/*
 * 
 */

var Define = require("../../lib/Define.js")

var _phone = null;

Page({
  data:{},
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  onPhoneInput:function(e){
    _phone = e.detail.value
  },
  onNextBtnClick:function(){
    if(Define.checkMobile(_phone)){
      wx.showLoading({
        title: '加载中...',
        mask:true
      })

      wx.request({
        url: Define.value.baseUrl+"/app/user/sendsmscode",
        data: {
          phone:_phone,
          bid:Define.value.bid
        },
        header:{
          'content-type':'application/x-www-form-urlencoded'
        },
        method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
        complete: function(res) {
          
          wx.hideLoading()

          if(res.data.code == 200){
            wx.redirectTo({
              url: 'setsmscode?phone='+_phone
            })
          }else{
            wx.showModal({
              title: '提示',
              content: res.data.msg
            })
          }
        }
      })

    }else{
      wx.showToast({
        title: '请输入正确的电话号码',
        image:"/images/theme_d/toasterr.png"
      })
    }
  }
})